
<template>
<div>
<!-- <p-modal
    :width="width"
    :title="title"
    :visible="visible"
    @cancel="closeModal"
    @ok="handleOk"
    cancelText="关闭"> -->

    <!-- 查询区域 -->
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper" v-if="show==='default'">
      <p-form layout="inline">
        <p-row :gutter="24">
          <p-col :xl="6" :lg="7" :md="8" :sm="24">
            <p-form-item label="工艺路线">
              <p-select :default-value="tagList[0].value" placeholder="请选择工艺路线" v-model="processRouter">
                <p-select-option v-for="item in tagList" :key="item+'tag'" :value="item.value">
                  {{ item.label }}
                </p-select-option>
              </p-select>
            </p-form-item>
          </p-col>
          <p-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <p-button type="primary" @click="handleImport">导入</p-button>
            </span>
          </p-col>

        </p-row>
      </p-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">

      <template v-if="cgButtonList && cgButtonList.length>0" v-for="(item,index) in cgButtonList">
          <p-button
            v-if=" item.optType=='js' && (item.groupTag == null || item.groupTag == '' )"
            :key=" 'cgbtn'+index "
            @click="cgButtonJsHandler(item.buttonCode)"
            type="primary"
            :icon="item.buttonIcon"
          >{{ item.buttonName }}</p-button>
          <p-button
            v-else-if=" item.optType=='action' && (item.groupTag == null || item.groupTag == '' )"
            :key=" 'cgbtn'+index "
            @click="cgButtonActionHandler(item.buttonCode)"
            type="primary"
            :icon="item.buttonIcon"
          >{{ item.buttonName }}</p-button>
      </template>

        <!-- 高级查询区域 -->

      <p-dropdown  v-for="(item,index) in groupTag" :key="index">
        <p-button >
          {{item.name}}
          <p-icon type="down" />
        </p-button>
          <p-menu slot="overlay"  >
            <template  v-for="(items,indexs) in item.data">
              <p-menu-item v-if=" items.optType=='js' " :key="indexs" @click="cgButtonJsHandler(items.buttonCode)">
                <p-icon :type="items.buttonIcon" />{{items.buttonName}}
              </p-menu-item>
              <p-menu-item v-else-if=" items.optType=='action' " :key="indexs" @click="cgButtonActionHandler(items.buttonCode)">
                <p-icon :type="items.buttonIcon" />{{items.buttonName}}
              </p-menu-item>
            </template>
          </p-menu>
      </p-dropdown>

      <p-dropdown v-if="selectedRowKeys.length > 0">
        <p-menu slot="overlay">
          <p-menu-item key="1" @click="batchDel"><p-icon type="delete"/>删除</p-menu-item>
        </p-menu>
        <p-button style="margin-left: 8px"> 批量操作 <p-icon type="down" /></p-button>
      </p-dropdown>
    </div>
    <!-- table区域-begin -->
    <div>
        <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
            <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
            <a style="margin-left: 24px" @click="onClearSelected">清空</a>

            <span style="float:right;">
              <a @click="initLoadData()"><p-icon type="sync" />刷新</a>
              <p-divider type="vertical" />
                <p-popover title="自定义列" trigger="click" placement="leftBottom"  :overlay-style="getWidth">
                <template slot="content">
                  <p-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
                    <p-row>
                      <template v-for="(item,index) in defColumns">
                        <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                            <p-col :span="12"><p-checkbox :value="item.dataIndex">{{ item.title }}</p-checkbox></p-col>
                        </template>
                      </template>
                    </p-row>
                  </p-checkbox-group>
                </template>
                <a><p-icon type="setting" />自定义列</a>
              </p-popover>
            </span>
        </div>


      <p-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :scroll="tableScroll"
        :dataSource="dataSourceList"
        :pagination="ipagenation"
        :loading="loading"
        :customRow="clickThenSelect"
        @change="handleTableChange">
          
           <template slot="processTowid" slot-scope="text,record">
             {{text}}
           </template>
           <template slot="processTowcode" slot-scope="text,record">
             <span  style="margin-right:5px;">{{text}}</span><p-icon class="iconShow" type="edit" />
             <div>
                <!-- <p-input v-model="record.processTowcode"></p-input> -->
             </div>
           </template>
           <template slot="processTowname" slot-scope="text,record">
             {{text}}
             <!-- <p-input v-model="record.processTowname"></p-input> -->
           </template>
           <template slot="manhour" slot-scope="text,record">
             {{text}}
             <!-- <p-input v-model="record.manhour"></p-input> -->
           </template>
           <template slot="mname" slot-scope="text,record">
             {{text}}
             <!-- <p-input v-model="record.mname"></p-input> -->
           </template>
           <template slot="bomDosage" slot-scope="text,record">
             {{text}}
             <!-- <p-input v-model="record.bomDosage"></p-input> -->
           </template>
           <template slot="unit" slot-scope="text,record">
             {{text}}
             <!-- <p-input v-model="record.unit"></p-input> -->
           </template>

            <span slot="action" slot-scope="text, record" v-if="show==='default'">
              <a @click="handleEdit(record)">编辑</a>

              <p-popconfirm
                title="是否删除这一条数据?"
                ok-text="Yes"
                cancel-text="No"
                @confirm="toDelete(record)"
              >
                <p-button type="link">删除</p-button>
              </p-popconfirm>
            </span>
      </p-table>
    </div>
    <!-- <section slot="footer">
      <p-button @click="toBack">回退</p-button>
      <p-button @click="handleSave">保存</p-button>
      <p-button @click="toApprove">提交</p-button>
    </section> -->
  <!-- </p-modal> -->

  <p-modal 
  title="编辑"
  v-model="editVisible"
  width="400px"
  @ok="handleEditOk">
  <p-form-model ref="ruleForm" :model="editformData" :label-col="labelCol" :wrapper-col="wrapperCol">
      <p-row :guter="20">
          <p-col :span="24">
              <p-form-model-item label="二级工序">
                <!-- <p-input  style="width:200px"  v-model="editformData.versionNum"  /> -->
                <p-select style="width:200px" v-model="editformData.processTowcode" @change="secondDefChange">
                  <p-select-option :value="item.processmcode" v-for="item in secondDefList" :key="item.processmcode+'zdbc'">
                    {{item.processmname}}
                  </p-select-option>
                </p-select>
              </p-form-model-item>
              <!-- <p-form-model-item label="工站编码">
                <p-input  style="width:200px"  v-model="editformData.versionNum"  />
              </p-form-model-item> -->
              <p-form-model-item label="工站名称">
                <!-- <p-input  style="width:200px"  v-model="editformData.versionNum"  /> -->
                <p-select style="width:200px" v-model="editformData.workstationcode" @change="stationChange">
                  <p-select-option :value="item.processmcode" v-for="item in stationList" :key="item.processmcode+'zbc'">
                    {{item.processmname}}
                  </p-select-option>
                </p-select>
              </p-form-model-item>
              <p-form-model-item label="标准工时">
                <p-input-number style="width:200px"  v-model="editformData.manhour" :precision="0" :min="0" />
              </p-form-model-item>
              <p-form-model-item label="物料名称">
                <p-input  style="width:200px"  v-model="editformData.mname"  />
              </p-form-model-item>
              <p-form-model-item label="BOM用量">
                <p-input-number style="width:200px" v-model="editformData.bomDosage" :precision="3" :min="0" />
              </p-form-model-item>
              <p-form-model-item label="计量单位">
                  <p-input  style="width:200px"  v-model="editformData.unit"  />
              </p-form-model-item>
          </p-col>
      </p-row>
    </p-form-model>
  </p-modal>
  </div>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import {api} from '@/api/manage'
  import JSuperQuery from '@/components/jeecg/JSuperQuery.vue'
  import { filterObj } from '@/utils/util'
  import Vue from 'vue'
  import {initDictOptions, filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import ButtonExpHandler from '@/components/jeecgbiz/modules/ButtonExpHandler'
  import { postAction,getAction,deleteAction } from '@/api/manage'
  import FxCompontensModal from "@/components/jeecgbiz/FxCompontensModal"
import { putAction } from '../../../../../../api/manage'

  //高级查询modal需要参数
    const superQueryFieldList=[
            {
                value:'scientificOrder',
                text: '任务编号',
                type: 'string'
            },
            {
                value:'scientificPlease',
                text: '申请人',
                type: 'select',
                dictCode: ''
            },
            {
                value:'dptname',
                text: '部门名称',
                type: 'select',
                dictCode: ''
            },
            {
                value:'scientificContact',
                text: '联系方式',
                type: 'string'
            },
            {
                value:'scientificno',
                text: '项目编码',
                type: 'string'
            },
            {
                value:'scientificname',
                text: '项目名称',
                type: 'string'
            },
            {
                value:'scientificClassification',
                text: '科研分类',
                type: 'string'
            },
            {
                value:'scientificType',
                text: '加工类型',
                type: 'select',
                dictCode: 'mes_scientific_type'
            },
            {
                value:'name',
                text: '名称',
                type: 'string'
            },
            {
                value:'contentTime',
                text: '需求完成时间',
                type: 'string'
            },
            {
                value:'model',
                text: '型号/图号（版号）',
                type: 'string'
            },
            {
                value:'scientificStarttime',
                text: '计划开始时间',
                type: 'string'
            },
            {
                value:'scientificQitime',
                text: '实际物料齐套时间',
                type: 'string'
            },
            {
                value:'scientificState',
                text: '当前状态',
                type: 'select',
                dictCode: 'mes_ba_Scientific'
            },
            {
                value:'bomReport',
                text: 'BOMreport',
                type: 'string'
            },
            {
                value:'researchBom',
                text: '科研bom表',
                type: 'string'
            },
            {
                value:'accessory',
                text: '附件',
                type: 'string'
            },
            {
                value:'supno',
                text: '供应商编码',
                type: 'string'
            },
            {
                value:'supname',
                text: '供应商名称',
                type: 'string'
            },
            {
                value:'scientificCompleteTime',
                text: '事业部计划完成时间',
                type: 'Date'
            },
            {
                value:'actualStartTime',
                text: '事业部实际领用开始时间',
                type: 'Date'
            },
            {
                value:'actualFinishTime',
                text: '事业部实际完成时间',
                type: 'Date'
            },
            {
                value:'actualCompletion',
                text: '实际完成情况',
                type: 'select',
                dictCode: 'mes_actual_completion'
            },
            {
                value:'createBy',
                text: '创建人',
                type: 'string'
            },
            {
                value:'createTime',
                text: '创建日期',
                type: 'Date'
            },
            {
                value:'updateBy',
                text: '更新人',
                type: 'string'
            },
            {
                value:'updateTime',
                text: '更新日期',
                type: 'Date'
            },
    ]

  export default {
    name: "MesMfRoute",
    mixins:[JeecgListMixin],
    components: {
      JSuperQuery,

    },
    data () {
      return {
        fieldList:superQueryFieldList,
        superQueryFlag:false,
        width:1200,
        title:'工艺路线维护',
        processRouter:'001',
        visible:false,
        editVisible:false,
        tagList:[
        {label:'科研加工工艺编码',value:'001'},
        ],
        dataSourceList:[],
        formInfo:{},
        editformData:{},
        labelCol:{span:6},
        wrapperCol:{span:16},
        superQueryParams: '',
        description: '工艺路线维护',
        EnhanceJS:'',
        cgButtonLinkList:[],
        cgButtonList:[],
        title:'',//存表名
        groupTag:[],
        queryInfo: [],
        code: '',
        // 表头
        columns: [],
         //列设置
         settingColumns:[],
         //列定义
         defColumns: [
          {
            title: '二级工序',
            align: 'center',
            dataIndex: 'processTowname',
            scopedSlots: { customRender: 'processTowname' },
          },
          {
            title: '工站编码',
            align: 'center',
            dataIndex: 'workstationcode',
            scopedSlots: { customRender: 'workstationcode' },
          },
          {
            title: '工站名称',
            align: 'center',
            dataIndex: 'workstationname',
            scopedSlots: { customRender: 'workstationname' },
          },
          {
            title: '标准工时',
            align: 'center',
            dataIndex: 'manhour',
            scopedSlots: { customRender: 'manhour' },
          },
          {
            title: '物料编码',
            align: 'center',
            dataIndex: 'mcode',
            scopedSlots: { customRender: 'mcode' },
          },
          {
            title: '物料名称',
            align: 'center',
            dataIndex: 'mname',
            scopedSlots: { customRender: 'mname' },
          },
          {
            title: 'BOM用量',
            align: 'center',
            dataIndex: 'bomDosage',
            scopedSlots: { customRender: 'bomDosage' },
          },
          {
            title: '计量单位',
            align: 'center',
            dataIndex: 'unit',
            scopedSlots: { customRender: 'unit' },
          },
          {
            title: '插件位置',
            align: 'center',
            dataIndex: 'positionName',
            scopedSlots: { customRender: 'positionName' },
          },
          {
            title: '规格',
            align: 'center',
            dataIndex: 'sprc',
            scopedSlots: { customRender: 'sprc' },
          },
          {
            title: '代替组',
            align: 'center',
            dataIndex: 'groupName',
            scopedSlots: { customRender: 'groupName' },
          },
          {
            title: '优先等级',
            align: 'center',
            dataIndex: 'levelName',
            scopedSlots: { customRender: 'levelName' },
          },
          {
            title: '备注',
            align: 'center',
            dataIndex: 'remark',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed:'right',
            width:130,
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: '/mes-manufacture/mfProcessRouteMaintenance/list',
          delete: '/mes-manufacture/mfProcessRouteMaintenance/',
          deleteBatch: '/mes-manufacture/auto/mesMfScientific/deleteBatch',
          exportXlsUrl: '/mes-manufacture/mfProcessRouteMaintenance/export',
          importExcelUrl: '/mes-manufacture/mfProcessRouteMaintenance/import',
          getColumns: '/mes-manufacture/mfScientific/list',
          buttonAction: '/mes-manufacture/online/cgform/api/doButton',
          toBack:'/mes-manufacture/mfProcessRouteMaintenance/back/',
          submit:'/mes-manufacture/mfProcessRouteMaintenance/approve/', 
          editRouteMain:'/mes-manufacture/mfProcessRouteMaintenance',
          getAllSecondDef:'/mes-craft/craft/mesPeDefinition/getAllSecondDef',//所有二级工序
          getAllStation:'/mes-craft/craft/mesPeDefinition/getAllStation',//所有工站
        },
        dictOptions:{
         dptname:[],
         scientificType:[],
         scientificState:[],
         actualCompletion:[],
        },
        /* 分页参数 */
        ipagenation:{
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '50'],
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条"
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        projectId:'',
        selectedMainId:'',
        secondDefList:[],
        stationList:[],
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${api.test}${this.url.importExcelUrl}`;
      },
      getWidth:function(){
        if(this.defColumns.length > 14){
          return {width : '500px'}
        }
      },
      newSelectedMainId:function(){
        if(typeof(this.selectedMainId) == 'number'){
          return this.selectedMainId.toString()
        }else{
          return this.selectedMainId
        }
      },
			tableScroll:function(){
			 if(this.columns.length > 10){
					return { x: this.columns.length*150-450 }
				}
			}
    },
    props:{
      scientificId:{
        type:String,
        default:''
      },
      show:{
        type:String,
        default:'default'
      }
    },
     created() {
       console.log(this.scientificId)
          // this.initButtonList();
          this.getAllSecondDef();
          this.getAllStation();
          this.initColumns();
          this.setdefColumns();   
          this.initLoadData()   
     },
     mounted(){
      
     },
     watch:{
      scientificId(newVal){
        console.log(newVal)
          this.initLoadData() 
      },
    },

    methods: {
        openModal(projectId){
          this.projectId = projectId
          this.visible = true
      },
      //所有二级工序
      getAllSecondDef(){
        getAction(this.url.getAllSecondDef).then(res=>{
          if(res.code === 0){
            this.secondDefList = res.data || []
          }
        })
      },
      //所有工站
      getAllStation(){
        getAction(this.url.getAllStation).then(res=>{
           if(res.code === 0){
            this.stationList = res.data || []
          }
        })
      },
      secondDefChange(val,row){
        console.log(val,row)
        this.editformData.processTowname = row.componentOptions.children[0].text
        },
      stationChange(val,row){
        console.log(val,row.componentOptions.children[0].text)
        this.editformData.workstationname = row.componentOptions.children[0].text
        },
      //工艺维护导入操作 
      // secondDefList
      handleImport(){
       const url = '/mes-manufacture/mfProcessRouteMaintenance/import'
       const info={
         mesMfScientificId:this.scientificId,
         processTowcode:this.secondDefList[0].processmcode,
         processTowname:this.secondDefList[0].processmname
       }
       this.loading = true;
       postAction(url,info).then(res=>{
         if(res.code === 0){
          this.$message.success('导入成功')
          this.initLoadData()
         }else if(res.code === 5025){
           this.loading = false;
          this.$message.warning(res.msg)
         }
       })
      },
      //分页
      handleTableChange(pagination, filters, sorter) {
      // 分页、排序、筛选变化时触发
      // TODO 筛选
      if (Object.keys(sorter).length > 0) {
        this.isorter.column = sorter.field
        this.isorter.order = sorter.order == 'ascend' ? 'asc' : 'desc'
      }
      this.ipagenation = pagination
      this.initLoadData()
    },
      closeModal(){
	  	this.visible = false;
      },
      handleOk(){

      },
      handleEdit(row){
        console.log(row)
        this.editformData = Object.assign({},row)
        this.editVisible = true
      },
      //修改工艺维护路线
      handleEditOk(){
        console.log(this.editformData)
         putAction(this.url.editRouteMain,this.editformData).then(res=>{
            if(res.code === 0){
              this.editVisible = false
              this.$message.success('操作成功')
              this.initLoadData()
            }
         })
      },
      toDelete(row){
         deleteAction(this.url.delete+row.id).then(res=>{
           if(res.code === 0){
             this.$message.success('操作成功')
             this.initLoadData()
           }

         })
      },
      //保存
      handleSave(){

      },
      toBack(){
          getAction(this.url.toBack+this.projectId,'get').then(res=>{
             if(res.code === 0){
               this.$message.success('操作成功');
             }
             this.visible = false;
             this.modalFormOk()
          })
      },
      toApprove(){
          getAction(this.url.submit+this.projectId,'get').then(res=>{
             if(res.code === 0){
               this.$message.success('操作成功');
             }
             this.visible = false;
             this.modalFormOk()
          })
      },

    //   closeModal(){
    //      this.$refs.modalRoute.openModal()
    //   },
      toProcess(){
        this.$router.push({path:'/work/auto/modules/MesProcessRecord',query:{id:''}})
      },

      setdefColumns(){
        if(this.columns.length > 13){
          let arrLength = this.columns.length-1
          this.columns.forEach((item,index)=>{
            item["width"] = 130
          })
          this.columns[arrLength]['fixed'] = 'right'
          this.columns[0]['fixed'] = 'left'
          this.columns[1]['fixed'] = 'left'
        }
      },
      initColumns(){
        //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
        //this.defColumns = colAuthFilter(this.defColumns,'testdemo:');

        var key = this.$route.name+":colsettings";
        let colSettings= Vue.ls.get(key);
        if(colSettings==null||colSettings==undefined){
          let allSettingColumns = [];
          this.defColumns.forEach(function (item,i,array ) {
            allSettingColumns.push(item.dataIndex);
          })
          this.settingColumns = allSettingColumns;
          this.columns = this.defColumns;
        }else{
          this.settingColumns = colSettings;
          const cols = this.defColumns.filter(item => {
            if(item.key =='rowIndex'|| item.dataIndex=='action'){
              return true;
            }
            if (colSettings.includes(item.dataIndex)) {
              return true;
            }
            return false;
          })
          this.columns =  cols;
        }
      },
      //列设置更改事件
      onColSettingsChange (checkedValues) {
        var key = this.$route.name+":colsettings";
        Vue.ls.set(key, checkedValues, 7 * 24 * 60 * 60 * 1000)
        this.settingColumns = checkedValues;
        const cols = this.defColumns.filter(item => {
          if(item.key =='rowIndex'|| item.dataIndex=='action'){
            return true
          }
          if (this.settingColumns.includes(item.dataIndex)) {
            return true
          }
          return false
        })
        this.columns =  cols;
      },
        //高级查询方法
        handleSuperQuery(arg) {
            if(!arg){
                this.superQueryParams=''
                this.superQueryFlag = false
            }else{
                this.superQueryFlag = true
                this.superQueryParams=JSON.stringify(arg)
            }
            this.initLoadData()
        },
        // 获取查询条件
        getQueryParams() {
            let sqp = {}
            if(this.superQueryParams){
                sqp['superQueryParams']=encodeURI(this.superQueryParams)
            }
            var param = Object.assign(sqp, this.queryParam, this.isorter);
            param.field = this.getQueryField();
            param.pageNo = this.ipagenation.current;
            param.limit = this.ipagenation.pageSize;
            param.mesMfScientificId = this.scientificId;
            return filterObj(param);
        },
      initDictConfig(){
        initDictOptions('sys_depart,depart_name,id').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'dptname', res.data)
          }
        })
        initDictOptions('mes_scientific_type').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'scientificType', res.data)
          }
        })
        initDictOptions('mes_ba_Scientific').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'scientificState', res.data)
          }
        })
        initDictOptions('mes_actual_completion').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'actualCompletion', res.data)
          }
        })
      },
      clickThenSelect(record) {
        return {
          on: {
            click: (ev) => {
              // this.onSelectChange(record.id.split(","), [record]);
              console.log(ev)
            }
          }
        }
      },
      onClearSelected() {
        this.selectedRowKeys = [];
        this.selectionRows = [];
        this.selectedMainId=''
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedMainId=selectedRowKeys[0]
        this.selectedRowKeys = selectedRowKeys;
        this.selectionRows = selectionRows;
      },
      initLoadData(arg) {
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagenation.current = 1;
        }
        this.onClearSelected()
        var params = this.getQueryParams();//查询条件
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSourceList = res.data.records || [];
            this.ipagenation.total = res.data.total;
          }
          if(res.code===510){
            this.$message.warning(res.msg)
          }
           this.$emit('isHaveData',this.dataSourceList)
          this.loading = false;
        })
      },

      // 弹出窗组件
      showDemoModal() {
        this.$refs.modalCompon.modalShow();
      },
      // 点击btn获取数据
      btnGetData(tableName,title){
        getAction(`${this.url.getColumns}`,{
          tableName:tableName
        }).then(
          res=>{
            if(res.code == 0){
              this.queryInfo = res.data.columns
              this.title = title
              this.dictOptions = res.data.dictOptions
              this.showDemoModal()
            }else{
               this.$message.warning(res.msg);
            }
          }
        )
      },


      //筛选分组
      getGroupTag(arrList) {
        let arr = [];
        var map = {},
            dest = [];
        arrList.forEach((item, index) => {
          if (item.groupTag) {
            arr.push(item);
          }
        });
        for (var i = 0; i < arr.length; i++) {
          var ai = arr[i];
          if (!map[ai.groupTag]) {
            dest.push({
              groupTag: ai.groupTag,
              name: ai.groupName,
              data: [ai]
            });
            map[ai.groupTag] = ai;
          } else {
            for (var j = 0; j < dest.length; j++) {
              var dj = dest[j];
              if (dj.groupTag == ai.groupTag) {
                dj.data.push(ai);
                break;
              }
            }
          }
        }
        this.groupTag = dest
        console.log(dest);
      },
      showLinkButton(item,record){
          let btn = new ButtonExpHandler(item.exp,record);
          return btn.show;
      },
        initButtonList(){
          getAction(`${this.url.getColumns}8ac49ec7733bce48017355583fc9011e`).then((res)=>{
            console.log("--获取自定义按钮->>",res);
            if(res.success){
              this.code = res.data.code;
              this.initCgButtonList(res.data.cgButtonList);
              this.initCgEnhanceJs(res.data.enhanceJs);
              this.getGroupTag(res.data.cgButtonList);
            }else{
              this.$message.warning(res.msg)
            }
          })
        },
        initCgEnhanceJs(enhanceJs){
          //console.log("--onlineList-js增强",enhanceJs)
          if(enhanceJs){
            let Obj = eval ("(" + enhanceJs + ")");
            this.EnhanceJS = new Obj(getAction,postAction,deleteAction);
            this.cgButtonJsHandler('created')
          }else{
            this.EnhanceJS = ''
          }
        },
        initCgButtonList(btnList){
          let linkArr = []
          let buttonArr = []
          if(btnList && btnList.length>0){
            for(let i=0;i<btnList.length;i++){
              let temp = btnList[i]
              if(temp.buttonStyle=='button'){
                buttonArr.push(temp)
              }else if(temp.buttonStyle=='link'){
                linkArr.push(temp)
              }
            }
          }
          this.cgButtonLinkList = [...linkArr]
          this.cgButtonList=[...buttonArr]
          console.log("链接增强", this.cgButtonLinkList);
        },
        cgButtonJsHandler(buttonCode){
          if(this.EnhanceJS[buttonCode]){
            this.EnhanceJS[buttonCode](this)
          }
        },
        cgButtonActionHandler(buttonCode){
          //处理自定义button的 需要配置该button自定义sql
          if(!this.selectedRowKeys || this.selectedRowKeys.length==0){
            this.$message.warning("请先选中一条记录")
            return false
          }
          if(this.selectedRowKeys.length>1){
            this.$message.warning("请只选中一条记录")
            return false
          }
          let params = {
            formId:this.code,
            buttonCode:buttonCode,
            dataId:this.selectedRowKeys[0]
          }
          console.log("自定义按钮请求后台参数：",params)
          postAction(this.url.buttonAction,params).then(res=>{
            if(res.success){
              this.initLoadData()
              this.$message.success("处理完成!")
            }else{
              this.$message.warning("处理失败!")
            }
          })

        },
        cgButtonLinkHandler(record,buttonCode,optType){
          if(optType=="js"){
            if(this.EnhanceJS[buttonCode]){
              this.EnhanceJS[buttonCode](this,record)
            }
          }else if(optType=="action"){
            let params = {
              formId:this.code,
              buttonCode:buttonCode,
              dataId:record.id
            }
            console.log("自定义按钮link请求后台参数：",params)
            postAction(this.url.buttonAction,params).then(res=>{
              if(res.success){
                this.initLoadData()
                this.$message.success("处理完成!")
              }else{
                this.$message.warning("处理失败!")
              }
            })
          }
        },

    }
  }
  
</script>

<style scoped>
  @import '~@assets/less/common.less';
  .iconShow{
    display: none;
  }
  .iconShow:hover{
    display: block;
  }

</style>
